package controllers;

import business.DocumentBusiness;
import models.DocumentTO;

public class DocumentApplication extends Application {
	
	private static final String NOK_PATTERN_DOCUMENT = "Documento Fora do Padrao";
	
	public static void validarCPF(String cpf){
		DocumentTO document = new DocumentTO();
		document.document = cpf;
		//01874571155
		if(cpf==null || cpf.length()!=11){
			document.code=CODE_NOK_STATUS;
			document.description=NOK_PATTERN_DOCUMENT;
			document.uf=null;
		}try{
			document.isValid = DocumentBusiness.validarCPF(cpf);
			document.code=CODE_OK_STATUS;
			document.description=DESCRIPTION_OK_STATUS;
			document.uf=DocumentBusiness.verificarUFCPF(cpf);
		}catch (NumberFormatException e) {
			document.code=CODE_NOK_STATUS;
			document.description=NOK_PATTERN_DOCUMENT;
			document.uf=null;
			renderJSON(document);
		}
		renderJSON(document);
	}
	
	public static void validarCNPJ(String cnpj){
		System.out.println(cnpj);
		DocumentTO document = new DocumentTO();
		document.document = cnpj;
		//00233111000148
		if(cnpj==null || cnpj.length()!=14){
			document.code=CODE_NOK_STATUS;
			document.description=NOK_PATTERN_DOCUMENT;
			document.uf=null;
		}try{
			document.isValid = DocumentBusiness.validarCNPJ(cnpj);
			document.code=CODE_OK_STATUS;
			document.description=DESCRIPTION_OK_STATUS;
//			document.uf=DocumentBusiness.verificarUFCPF(cpf);
		}catch (NumberFormatException e) {
			document.code=CODE_NOK_STATUS;
			document.description=NOK_PATTERN_DOCUMENT;
			document.uf=null;
			renderJSON(document);
		}
		renderJSON(document);
	}
}
